home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 43.zip / Sources C- WorkDisk V.adf / iff / plopsound4.c < prev    next >
C/C++ Source or Header  |  1987-02-15  |  10KB  |  484 lines

  1. #include    <exec/types.h>
  2. #include        <exec/memory.h> /* soundprod */
  3.  
  4. #include    <graphics/gfx.h>
  5. #include        <graphics/sprite.h> /* voor sprites */
  6. #include    <intuition/intuition.h>
  7. #include     <stdio.h> /* ook voor soundprod */
  8. #include     "df1:iff/jiff.c"
  9.  
  10. #include "hardware/custom.h" /* soundprod */
  11.  
  12.  
  13. #define FRAMES        6
  14. #define SPRHEIGHT    16
  15. #define WORDSPERSPR    (2 * SPRHEIGHT + 4)
  16. #define MAXX        (XMAX-16)
  17. #define MAXY        (YMAX-16)
  18.  
  19. extern UWORD    ballmask[], ball0[];
  20. extern long    GetSprite();
  21.  
  22. UBYTE        idx[] = { 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4 };
  23. struct SimpleSprite    spr[FRAMES];
  24. UWORD        *sprbuf;
  25. UWORD        *sprites[FRAMES];
  26. int        vx[FRAMES], vy[FRAMES];
  27.  
  28.  
  29.  
  30. LONG filesize,s1,s2,per;
  31. char *filename;
  32. short *sndbuffer;
  33.  
  34.  
  35. /*This should be in exec/libraries.h */
  36. extern struct Library *OpenLibrary();
  37.  
  38. /*This should be in intuition/intuition.h */
  39. extern struct Screen *OpenScreen();
  40.  
  41. /* These are the bases for the libraries you need to do any graphics
  42.    much at all and still multi-task */
  43. struct Library *GfxBase = NULL;
  44. struct Library *LayersBase = NULL;
  45. struct Library    *IntuitionBase = NULL;
  46.  
  47. /* Well the workbench Screen isn't 320x200x5 so...*/
  48. struct Screen *PlopScreen = NULL;
  49.  
  50. /* Just one font for me... not static cause you might want it
  51.    in your menu modules. */
  52. struct TextAttr PlopFont =
  53.     {
  54.     "topaz.font",  /* I think this is the ROM font */
  55.     8,
  56.     0,
  57.     0,
  58.     };
  59.  
  60. /* a NewScreen - I don't know what half of this means either */
  61. static
  62. struct NewScreen PlopNewScreen =
  63.     {
  64.     0, 0, XMAX, YMAX, PLANES,
  65.     0, 1,
  66.     0,
  67.     CUSTOMSCREEN,
  68.     &PlopFont,
  69.     "AMY PRODUCTIONS !",
  70.     NULL,
  71.     NULL,
  72.     };
  73.  
  74. /* To use clip blit need a RastPort.  Pretty useless, a BitMap should
  75.    be enough I think ... or anyway something a little less massive */
  76. struct RastPort PlopRastPort;
  77. struct ViewPort *vp;
  78.  
  79. void
  80. put_ea_cmap(cmap, colors)
  81. unsigned char *cmap;
  82. long colors;
  83. {
  84. long i;
  85. unsigned long r, g, b;
  86.  
  87. if (colors > 32)    /*color clipping*/
  88.     colors = 32;
  89.  
  90. /* This loop is modified to work with Aztec 3.4a 32bit by J. Van Houtven */
  91. /* Modification Date : 20 July 1987 */
  92.  
  93. for (i=0; i<colors; i++)
  94.     {
  95.          r= *cmap++ >> 4;
  96.          g= *cmap++ >> 4;
  97.          b= *cmap++ >> 4;
  98.          SetRGB4(&PlopScreen->ViewPort,i,(long)r,(long)g,(long)b);
  99.     }
  100. }
  101.  
  102.  
  103. main(argc, argv)
  104. int argc;
  105. char *argv[];
  106. {
  107. int i,j,x,y,offset = 0, flag = 0, speed;
  108. struct ILBM_info *info;
  109.  
  110. /* aanroep van sound routine */
  111.  
  112. custom.dmacon = 0x0003;
  113. per = 280;
  114. filename = "TAON_1";
  115. filesize = 42676;
  116. MakeSound();
  117.  
  118.  
  119. if ((GfxBase =  OpenLibrary("graphics.library", (long)0)) == NULL)
  120.         return(-1);
  121.  
  122. if ((LayersBase =  OpenLibrary("layers.library", (long)0)) == NULL)
  123.     {
  124.     plop_cleanup();
  125.     return(-2);
  126.     }
  127.  
  128. if ((IntuitionBase =  OpenLibrary("intuition.library",(long) 0)) == NULL)
  129.     {
  130.     plop_cleanup();
  131.     return(-3);
  132.     }
  133.  
  134. if ( (PlopScreen = OpenScreen(&PlopNewScreen) ) == NULL)
  135.     {
  136.     plop_cleanup();
  137.     return(-4);
  138.     }
  139. vp = &(PlopScreen->ViewPort);
  140.  
  141. InitRastPort(&PlopRastPort);
  142. PlopRastPort.Mask = (1<<PLANES)-1;
  143. /*just play it safe in case someone tries to load 6 bit planes...*/
  144.  
  145. setupsprites ();
  146.  
  147.  
  148. for (x=1; x<argc; x++)
  149. {
  150.  if ( (info = read_iff(argv[x], 0) ) != NULL)
  151.  {
  152.   put_ea_cmap(&info->cmap, (1 << info->bitmap.Depth));
  153.   PlopRastPort.BitMap = &info->bitmap;
  154.   ClipBlit( &PlopRastPort, (long)0, (long)0,
  155.            &PlopScreen->RastPort, (long)info->header.x, (long)info->header.y,
  156.        (long)info->header.w, (long)info->header.h, (long)COPY_MINTERM);
  157.  
  158.  for (i=0; i<FRAMES; i+=2)
  159.  {
  160.     if (GetSprite ( &spr[i], (long) i+2 ) < 0)
  161.             plop_cleanup();
  162.     spr[i].x = 8*i;
  163.     spr[i].y = 8*i;
  164.     spr[i].height = SPRHEIGHT;
  165.     ChangeSprite (vp, &spr[i], sprites[i]);
  166.  }
  167.  for (i=1; i<FRAMES; i+=2)
  168.  {
  169.     if (GetSprite ( &spr[i], (long) i+2 ) < 0)
  170.             plop_cleanup();
  171.     spr[i].x = (16*(FRAMES-1)) - 16*(i==3)-32*(i==5);
  172.     spr[i].y = (16*(FRAMES-1)) - 16*(i==3)-32*(i==5);
  173.     spr[i].height = SPRHEIGHT;
  174.     ChangeSprite (vp, &spr[i], sprites[i]);
  175.  }
  176.  
  177.  speed = 4;
  178.  
  179.  for (i=0; i<FRAMES; i++)
  180.  {
  181.   vx[i]= vy[i]=speed;
  182.  }
  183.  
  184.  --speed;
  185.  
  186.  for(j=0;j<1000;j++)
  187.  {
  188.   WaitTOF ();
  189.   for (i=0; i<FRAMES; i++)
  190.   {
  191.    if((spr[i].x += vx[i]) >= MAXX-speed || spr[i].x <= speed)
  192.    {
  193.     vx[i] = -vx[i];
  194.    }
  195.  
  196.    if((spr[i].y += vy[i]) >= MAXY-speed || spr[i].y <= speed)
  197.    { 
  198.     vy[i] = -vy[i];
  199.    }
  200.   }
  201.  
  202.   /* Hey !!! ChangeSprite also MOVES the sprites !!!! */
  203.   for (i=0; i<FRAMES; i++) ChangeSprite (vp, &spr[i], sprites[idx[i+offset]]);
  204.  
  205.    /*  Rotate balls every other loop  */
  206.   if (flag = !flag) offset = (offset + 1) % 6;
  207.  
  208.  }
  209.  
  210.    /* cleanup sprites */
  211.   
  212.   for (i=0; i<FRAMES; i++)
  213.     if (spr[i].num) FreeSprite ((long) spr[i].num);
  214.  
  215.  
  216.  
  217.   SetAPen(&PlopScreen->RastPort,0);
  218.   for(j=0;j<100;j++)
  219.   {
  220.    Move(&PlopScreen->RastPort,0,j);Draw(&PlopScreen->RastPort,XMAX-1,j);
  221.    Move(&PlopScreen->RastPort,0,YMAX-1-j);Draw(&PlopScreen->RastPort,XMAX-1,YMAX-1-j);
  222.   }
  223.  
  224.   free_planes(&info->bitmap);
  225.   }
  226.  }
  227. plop_cleanup();
  228. }
  229. /* ====== end of main ======= */
  230.  
  231. plop_cleanup()
  232. {
  233. register int i;
  234.  
  235. custom.dmacon = 0x0003;
  236. if(sndbuffer)
  237.         FreeMem(sndbuffer,filesize);
  238.  
  239. for (i=0; i<FRAMES; i++)
  240.   if (spr[i].num) FreeSprite ((long) spr[i].num);
  241.  
  242. if (sprbuf)
  243.     FreeMem (sprbuf, 2L * WORDSPERSPR * FRAMES);
  244. if (PlopScreen != NULL)
  245.     CloseScreen(PlopScreen);
  246. if (IntuitionBase != NULL)
  247.     CloseLibrary(IntuitionBase);
  248. if (LayersBase != NULL)
  249.     CloseLibrary(LayersBase);
  250. if (GfxBase != NULL)
  251.     CloseLibrary(GfxBase);
  252. }
  253.  
  254.  
  255. MakeSound()
  256. {
  257. LoadSound();
  258. PlaySong();
  259. }  
  260.  
  261. LoadSound()
  262. {
  263. FILE *fopen(), *fp;
  264. SHORT *ptr;
  265. LONG i;
  266.  
  267. sndbuffer = AllocMem(filesize,MEMF_CHIP);
  268. ptr = sndbuffer;
  269.  
  270. custom . dmacon = 0x0003;
  271. fp = fopen(filename,"r");
  272. if (fp == NULL) return(0);
  273.  
  274. s1 = 0; s2 =filesize;
  275. for (i=0; i<s1; i++)
  276.     getc(fp);
  277.  
  278. for (i=s1/2; i<s2/2; i++)
  279.     {
  280.     *ptr++ = getc(fp)*256 + getc(fp);
  281.     }
  282.  
  283. fclose (fp);
  284. }
  285.  
  286. PlaySong()
  287. {
  288. custom . aud[0].ac_ptr = (UWORD *)sndbuffer;
  289. custom . aud[0].ac_len = s2/2-s1/2;
  290. custom . aud[0].ac_per = per;
  291. custom . aud[0].ac_vol = 64;
  292.  
  293. custom . aud[1].ac_ptr = (UWORD *)sndbuffer;
  294. custom . aud[1].ac_len = s2/2-s1/2;
  295. custom . aud[1].ac_per = per;
  296. custom . aud[1].ac_vol = 64;
  297.  
  298. custom . dmacon = 0x8203;
  299. }
  300.  
  301. setupsprites ()
  302. {
  303.     UWORD *cw;    /* current position in buffer of sprite images */
  304.     UWORD *maskp;    /* current position in ballmask             */
  305.     UWORD *ballp;    /* current position in ball0 data           */
  306.     int frame, scan;
  307.  
  308.     if (!(sprbuf = AllocMem (2L * WORDSPERSPR * FRAMES, MEMF_CHIP)))
  309.         plop_cleanup();
  310.  
  311.     cw = sprbuf;    /* current position at top of buffer */
  312.     ballp = ball0;    /* ... top of data to be interleaved */
  313.  
  314.     for (frame=0; frame<FRAMES; frame++) {
  315.         maskp = ballmask;    /* one mask for all frames */
  316.         sprites[frame] = cw;
  317.         *cw++ = 0;        /* poscntl */
  318.         *cw++ = 0;
  319.  
  320.         /* one word from ball0, one word from ballmask */
  321.         for (scan=0; scan<SPRHEIGHT; scan++) {
  322.             *cw++ = *maskp++;
  323.             *cw++ = *ballp++;
  324.         }
  325.         *cw++ = 0;    /* termination */
  326.         *cw++ = 0;
  327.     }
  328. }
  329.  
  330. #asm
  331. *:ts=8 bk=0
  332. _ballmask:
  333.     public    _ballmask
  334.  
  335.     dc.w    %0000011111100000
  336.     dc.w    %0001111111111000
  337.     dc.w    %0011111111111100
  338.     dc.w    %0111111111111110
  339.     dc.w    %0111111111111110
  340.     dc.w    %1111111111111111
  341.     dc.w    %1111111111111111
  342.     dc.w    %1111111111111111
  343.     dc.w    %1111111111111111
  344.     dc.w    %1111111111111111
  345.     dc.w    %1111111111111111
  346.     dc.w    %0111111111111110
  347.     dc.w    %0111111111111110
  348.     dc.w    %0011111111111100
  349.     dc.w    %0001111111111000
  350.     dc.w    %0000011111100000
  351.  
  352.  
  353. _ball0:
  354.     public    _ball0
  355.  
  356.     dc.w    %0000011001100000
  357.     dc.w    %0001100110011000
  358.     dc.w    %0011001111001100
  359.     dc.w    %0001110000111000
  360.     dc.w    %0011110000111100
  361.     dc.w    %0011100000011100
  362.     dc.w    %1100011111100011
  363.     dc.w    %1000011111100001
  364.     dc.w    %1000011111100001
  365.     dc.w    %1100011111100011
  366.     dc.w    %0011100000011100
  367.     dc.w    %0011110000111100
  368.     dc.w    %0001110000111000
  369.     dc.w    %0011001111001100
  370.     dc.w    %0001100110011000
  371.     dc.w    %0000011001100000
  372.  
  373.  
  374. _ball1:
  375.     public    _ball1
  376.  
  377.     dc.w    %0000010011000000
  378.     dc.w    %0001001100110000
  379.     dc.w    %0010011100011000
  380.     dc.w    %0001100001110010
  381.     dc.w    %0011100001111010
  382.     dc.w    %0111000001111001
  383.     dc.w    %1000111110000111
  384.     dc.w    %1000111110000011
  385.     dc.w    %1000111110000011
  386.     dc.w    %1000111110000111
  387.     dc.w    %0111000001111001
  388.     dc.w    %0011100001111010
  389.     dc.w    %0001100001110010
  390.     dc.w    %0010011100011000
  391.     dc.w    %0001001100110000
  392.     dc.w    %0000010011000000
  393.  
  394.  
  395. _ball2:
  396.     public    _ball2
  397.  
  398.     dc.w    %0000010011000000
  399.     dc.w    %0001001100110000
  400.     dc.w    %0000011000011000
  401.     dc.w    %0011000111100110
  402.     dc.w    %0010000111100010
  403.     dc.w    %0110000111110001
  404.     dc.w    %0001111000001110
  405.     dc.w    %0011111000001110
  406.     dc.w    %0011111000001110
  407.     dc.w    %0001111000001110
  408.     dc.w    %0110000111110001
  409.     dc.w    %0010000111100010
  410.     dc.w    %0011000111100110
  411.     dc.w    %0000011000011000
  412.     dc.w    %0001001100110000
  413.     dc.w    %0000010011000000
  414.  
  415.  
  416. _ball3:
  417.     public    _ball3
  418.  
  419.     dc.w    %0000000110000000
  420.     dc.w    %0000011001100000
  421.     dc.w    %0000110000110000
  422.     dc.w    %0110001111000110
  423.     dc.w    %0110001111000110
  424.     dc.w    %1100011111100011
  425.     dc.w    %0011100000011100
  426.     dc.w    %0111100000011110
  427.     dc.w    %0111100000011110
  428.     dc.w    %0011100000011100
  429.     dc.w    %1100011111100011
  430.     dc.w    %0100001111000010
  431.     dc.w    %0110001111000110
  432.     dc.w    %0000110000110000
  433.     dc.w    %0000011001100000
  434.     dc.w    %0000000110000000
  435.  
  436.  
  437. _ball4:        ; Batter takes first base
  438.     public    _ball4
  439.  
  440.     dc.w    %0000001100100000
  441.     dc.w    %0000110011001000
  442.     dc.w    %0001100001100000
  443.     dc.w    %0110011110001100
  444.     dc.w    %0100011110000100
  445.     dc.w    %1000111110000110
  446.     dc.w    %0111000001111000
  447.     dc.w    %0111000001111100
  448.     dc.w    %0111000001111100
  449.     dc.w    %0111000001111000
  450.     dc.w    %1000111110000110
  451.     dc.w    %0100011110000100
  452.     dc.w    %0110011110001100
  453.     dc.w    %0001100001100000
  454.     dc.w    %0000110011001000
  455.     dc.w    %0000001100100000
  456.  
  457.  
  458. _ball5:
  459.     public    _ball5
  460.  
  461.     dc.w    %0000001100100000
  462.     dc.w    %0000110011001000
  463.     dc.w    %0001100011100100
  464.     dc.w    %0100111000011000
  465.     dc.w    %0101111000011100
  466.     dc.w    %1001111000001110
  467.     dc.w    %1110000111110001
  468.     dc.w    %1100000111110001
  469.     dc.w    %1100000111110001
  470.     dc.w    %1110000111110001
  471.     dc.w    %1001111000001110
  472.     dc.w    %0101111000011100
  473.     dc.w    %0101111000011000
  474.     dc.w    %0001100011100100
  475.     dc.w    %0000110011001000
  476.     dc.w    %0000001100100000
  477.  
  478. #endasm
  479.  
  480.  
  481.  
  482.  
  483.  
  484.